/**
 * version: 1.1.19
 * author: minmin.cai <minmin.cai@wehotelglobal.com>
 * wiki: http://172.25.62.87:10000/#/
 */

var ua = {}

let { screenWidth, screenHeight, platform } = uni.getSystemInfoSync()

switch (platform) {
  case 'ios':
    ua.isAndroid = false
    ua.isIOS = true
    break
  case 'android':
  default:
    ua.isAndroid = true
    ua.isIOS = false
}

if (ua.isIOS && screenHeight >= 812 && screenWidth >= 375) {
  ua.isIphoneX = true
}

 // #ifdef H5
 /**
 * 获取环境变量
 * @param  {String} ua navigator.userAgent
 * @return {Object} 包含各种环境判断的 UA
 */
ua = (function (useragent) {
  useragent = useragent.toLowerCase()
  if (useragent) {
    return {
      ...ua,
      isMobile: /applewebkit.*mobile.*/gi.test(useragent), // 是否移动设备
      isWXh5: /micromessenger/gi.test(useragent), // 是否运行于微信环境h5
      isAppWebview: /(botao)|jinjiang|wehotel|mdt/gi.test(useragent), // 是否 运行于app内webview
      isBotaoWebview: /wehotel\sbotao/gi.test(useragent), // 是否 运行于铂涛app内webview
      isJinjiangWebview: /jinjiang/gi.test(useragent), // 是否 运行于锦江pp内webview
      isMDTWebview: /mdt/gi.test(useragent), // 是否 运行于门店通pp内webview
      isMPWebview: (function isMPWebview() { // 是否 运行于小程序webview
        let inWxMp = /miniProgram/i.test(useragent) || /micromessenger/i.test(useragent)
        let inQQMp = /QQ/gi.test(useragent) && /miniprogram/gi.test(useragent)
        let inBdMp = /swan/gi.test(useragent)
        let inAlipayMp = /alipayclient/gi.test(useragent)
        let inToutiaoMp = /toutiaomicroapp/gi.test(useragent)

        return inWxMp || inQQMp || inBdMp || inAlipayMp || inToutiaoMp
      })(),
      isMP: false // 是否是小程序
    }
  }
})(navigator.userAgent)
 // #endif


 // #ifdef MP
ua = {
  ...ua,
  isMobile: false,
  isWxWebview: false,
  isInApp: false,
  isBotaoWebview: false,
  isJinjiangWebview: false,
  isMDTWebview: false,
  isMPWebview: false,
  isMP: true
}
 // #endif

export default ua
